<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <a-form-item :label="$t('业务时间')">
              <a-date-picker
                :placeholder="$t('请选择开始时间')"
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                class="query-group-cust"
                v-model="queryParam.createTimeBegin"
              ></a-date-picker>
              <span class="query-group-split-cust"></span>
              <a-date-picker
                :show-time="{ defaultValue: moment('23:59:59', 'HH:mm:ss') }"
                valueFormat="YYYY-MM-DD HH:mm:ss"
                :placeholder="$t('请选择结束时间')"
                class="query-group-cust"
                v-model="queryParam.createTimeEnd"
              ></a-date-picker>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('业务类型')">
                <j-dict-select-tag
                  :placeholder="$t('请选择业务类型')"
                  v-model="queryParam.typeId"
                  dictCode="bis_order.type"
                />
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('会员信息')">
                <a-input :placeholder="$t('请输入手机号/卡号/姓名/邮箱')" v-model="queryParam.memberInfo"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('支付方式')">
                <a-select v-model="queryParam.payType" :placeholder="$t('请选择')">
                  <a-select-option :value="item.name" :key="index" v-for="(item, index) in paytypeList">{{
                    item.nameText
                  }}</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item :label="$t('设备名称(编码)')">
                <a-select show-search :filter-option="false" @search="handleSearch" v-model="queryParam.deviceId" :placeholder="$t('请选择')">
                  <a-select-option :value="item.id" :key="index" v-for="(item, index) in deviceList">
                    <span>{{ item.name }}</span>
                    <span v-if="item.name != $t('全部')">({{ item.id }})</span>
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="10" :lg="11" :md="12" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">{{$t('查询')}}</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">{{$t('重置')}}</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? $t('收起') : $t('展开') }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
              <a-button
              v-has="'DeviceRecordController:export'"
                style="margin-left: 8px"
                type="primary"
                :loading="exloading"
                @click="handleExportXls($t('设备业务明细'))"
                >{{ $t('导出') }}</a-button
              >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true, y: tableHeight }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customHeaderRow="customHeaderRow"
        :customRow="customRow"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无图片') }}</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">{{ $t('无文件') }}</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            {{ $t('下载') }}
          </a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">{{ $t('编辑') }}</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">{{ $t('更多') }} <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">{{ $t('详情') }}</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm :title="$t('确定删除吗?')" @confirm="() => handleDelete(record.id)">
                  <a>{{ $t('删除') }}</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import moment from 'moment'
import { getAction } from '@/api/manage'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { initDictOptions } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'DeviceBusinessDetails',
  mixins: [JeecgListMixin, mixinDevice],
  components: {},
  data() {
    return {
      description: '设备业务明细页面',
      moment,
      // 表头
      columns: [
        {
          title: this.$t('业务时间'),
          align: 'center',
          dataIndex: 'createTime',
          width: 180,
        },
        {
          title: this.$t('业务类型'),
          align: 'center',
          dataIndex: 'typeId_dictText',
          width: 146,
        },
        {
          title: this.$t('手机号'),
          align: 'center',
          dataIndex: 'phone',
          width: 120,
        },
        {
          title: this.$t('卡号'),
          align: 'center',
          dataIndex: 'chipNo',
          width: 120,
        },
        {
          title: this.$t('邮箱'),
          align: 'center',
          dataIndex: 'email',
          width: 160,
        },
        {
          title: this.$t('姓名'),
          align: 'center',
          dataIndex: 'name',
          width: 120,
        },
        {
          title: this.$t('支付方式'),
          align: 'center',
          dataIndex: this.$t('payTypeName'),
          width: 140,
        },
        {
          title: this.$t('交易金额'),
          align: 'right',
          dataIndex: 'payAmount',
          width: 120,
          customRender: (text, r) => {
            return text.toFixed(2);
          }
        },
        {
          title: this.$t('设备编码'),
          align: 'center',
          dataIndex: 'deviceId',
          width: 140,
        },
        {
          title: this.$t('设备名称'),
          align: 'center',
          dataIndex: 'deviceName',
          width: 140,
        },
      ],
      url: {
        list: '/device/deviceRecord/list',
        exportXlsUrl: '/device/deviceRecord/exportXls',
      },
      paytypeList: [],
      deviceList: [],
      queryParam: {
        payType: '',
        deviceId: '',
      },
      hideCond: 1
    }
  },
  created() {
    if (localStorage.getItem('operateCoin') == 1) {
      this.columns.splice(this.columns.length - 2, 0, {
        title: this.$t('交易币'),
        align: 'right',
        dataIndex: 'coinValue',
        width: 120,
          customRender: (text, r) => {
            return text.toFixed(2);
          }
      },
      {
        title: this.$t('交易后币'),
        align: 'right',
        dataIndex: 'coinAfter',
        width: 120,
        customRender: (text, r) => {
          return text.toFixed(2);
        }
      })
    }
    if (localStorage.getItem('operateLottery') == 1) {
      this.columns.splice(this.columns.length - 2, 0, {
        title: this.$t('交易彩票'),
        align: 'right',
        dataIndex: 'lotteryValue',
        width: 120,
          customRender: (text, r) => {
            return text.toFixed(0);
          }
      },
      {
        title: this.$t('交易后彩票'),
        align: 'right',
        dataIndex: 'lotteryAfter',
        width: 120,
        customRender: (text, r) => {
          return text.toFixed(0);
        }
      })
    }
    if (localStorage.getItem('operateACoin') == 1) {
      this.columns.splice(this.columns.length - 2, 0, {
        title: this.$t('交易A币'),
        align: 'right',
        dataIndex: 'pointsValue',
        width: 120,
          customRender: (text, r) => {
            return text.toFixed(0);
          }
      },
      {
        title: this.$t('交易后A币'),
        align: 'right',
        dataIndex: 'pointsAfter',
        width: 120,
        customRender: (text, r) => {
          return text.toFixed(0);
        }
      })
    }
    if (localStorage.getItem('operateALottery') == 1) {
      this.columns.splice(this.columns.length - 2, 0, {
        title: this.$t('交易A票'),
        align: 'right',
        dataIndex: 'alotteryValue',
        width: 120,
          customRender: (text, r) => {
            return text.toFixed(0);
          }
      },
      {
        title: this.$t('交易后A票'),
        align: 'right',
        dataIndex: 'alotteryAfter',
        width: 120,
        customRender: (text, r) => {
          return text.toFixed(0);
        }
      })
    }
    if (localStorage.getItem('operateCredit') == 1) {
      this.columns.splice(this.columns.length - 2, 0, {
        title: this.$t('交易积分'),
        align: 'right',
        dataIndex: 'integralValue',
        width: 120,
          customRender: (text, r) => {
            return text.toFixed(0);
          }
      },
      {
        title: this.$t('交易后积分'),
        align: 'right',
        dataIndex: 'integralAfter',
        width: 120,
        customRender: (text, r) => {
          return text.toFixed(0);
        }
      })
    }
  },
  mounted() {
    let that = this
    document.onkeydown = function (e) {
      let key = window.event.keyCode
      if (key == 75 && event.ctrlKey) {
        window.event.preventDefault()
        that.isHideData = false
        that.queryParam.dataType = 0
        that.searchQuery()
      }
    }
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {
      let param = {}
      param.pageNo = 1
      param.pageSize = 9999
      param.state = 'Y'
      getAction('/pay/bisPayType/list', param).then((res) => {
        if (res.success) {
          this.paytypeList = res.result.records
          this.paytypeList.unshift({ name: '', nameText: this.$t('全部') })
        }
      })
      this.customInit()
    },
    handleSearch(value) {
      let query = {}
      if (value) {
        query.deviceInfo = value
      }
      getAction('/device/bisDeviceInfo/list', query).then((res) => {
        if (res.success) {
          this.deviceList = res.result.records
          this.deviceList.unshift({ id: '', name: this.$t('全部') })
        }
      })
    },
    searchReset() {
      this.queryParam = {
        payType: '',
        deviceId: '',
      }
      this.selectedRowIndex = []
      this.customInit()
    },
    customInit() {
      this.handleSearch()
      this.isHideData = true
      this.queryParam.dataType = 2
      this.loadData(1)
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>